﻿Ext.define('HIT.controller.RuleSet', {
	extend : 'Ext.app.Controller',
	views : [ 'SetRuleSelectPanel' ],

	onButtonClick : function(button, e, options) {
		if (button.id == 'set-regulars-save') {
			
			//获得每个框的选中状态
			var rule1 = Ext.getCmp('set-regulars-check-1').getValue() == true ? 1 : 0;
			var rule2 = Ext.getCmp('set-regulars-check-2').getValue() == true ? 1 : 0;
			var rule3 = Ext.getCmp('set-regulars-check-3').getValue() == true ? 1 : 0;
			var rule4 = Ext.getCmp('set-regulars-check-4').getValue() == true ? 1 : 0;
			var rule5 = Ext.getCmp('set-regulars-check-5').getValue() == true ? 1 : 0;
			var rule6 = Ext.getCmp('set-regulars-check-14').getValue() == true ? 1 : 0;
			var rule7 = Ext.getCmp('set-regulars-check-6').getValue() == true ? 1 : 0;
			var rule8 = Ext.getCmp('set-regulars-check-7').getValue() == true ? 1 : 0;
			var rule9 = Ext.getCmp('set-regulars-check-8').getValue() == true ? 1 : 0;
			var rule10 = Ext.getCmp('set-regulars-check-9').getValue() == true ? 1 : 0;
			var rule11 = Ext.getCmp('set-regulars-check-10').getValue() == true ? 1 : 0;
			var rule12 = Ext.getCmp('set-regulars-check-11').getValue() == true ? 1 : 0;
			var rule13 = Ext.getCmp('set-regulars-check-12').getValue() == true ? 1 : 0;
			Share.AjaxRequest({
				url : ctx + '/ruleSet',
				sync:false,
				params : {
					rule1 : rule1,
					rule2 : rule2,
					rule3 : rule3,
					rule4 : rule4,
					rule5 : rule5,
					rule6 : rule6,
					rule7 : rule7,
					rule8 : rule8,
					rule9 : rule9,
					rule10 : rule10,
					rule11 : rule11,
					rule12 : rule12,
					rule13 : rule13
				},
				callback : function(json) {
					if(rule1=="0"&&rule2=="0"&&rule3=="0"&&rule4=="0"&&rule5=="0"&&rule6=="0"&&rule7=="0"&&rule8=="0"&&rule9=="0"&&rule10=="0"&&rule12=="0"&&rule13=="0"&&rule11=="0"){						
						//没有规则被选中
						Share.ShowMessage("I0064",'规则将不会执行。');
					} else {
						Ext.MessageBox.confirm(Share.T('提示'), Share.T('设置成功。请到【规则顺序】页面重新指定规则执行顺序'),function(btn){
							if(btn == 'yes'){ 
								var node =
						        {    
						            "data" : { "id" : "set-regularorder","text" : Share.T('规则顺序'), "iconCls" : "tj-tree-file"}
						        };
								Ext.getCmp('centertabpanel').doLayout();
								var orderPanel = Ext.getCmp('tab-set-regularorder');
								if (!orderPanel) {
									
								} else {
									orderPanel.close();
								}
								Share.opentTabByPanel(node, 'widget.setregularorder');
							} else{
								Share.ShowMessage("I0045");
							}
						});
					}
				},
				falseFun : function(json) {
					Share.ShowMessage("I0007","设置");
				}
			});
			}
	},
	init : function(application) {
		this.control({
			"button" : {
				click : this.onButtonClick
			}
		});
	}
});
